package cn.icanci.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @Author: icanci
 * @ProjectName: Spring-Boot-Cases
 * @PackageName: cn.icanci.swagger.config
 * @Date: Created in 2020/7/18 10:31
 * @ClassAction: Swagger 配置文件 配置API文档分组
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig05 {

    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("A");
    }

    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("B");
    }

    @Bean
    public Docket docket3() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("c");
    }

    /**
     * 配置Swagger的bean实例
     *
     * @return 返回 Docket 对象
     */
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 配置 要扫描接口的方式：RequestHandlerSelectors
                // 配置 需要扫描的包：basePackage
                // 扫描全部 ： any()
                // 扫描类上的注解：withClassAnnotation() 注解的反射对象
                // 扫描方法上的注解：withMethodAnnotation
                .apis(RequestHandlerSelectors.basePackage("cn.icanci.swagger.controller"))
                // 过滤路径：paths()
                .paths(PathSelectors.ant("/icanci/**"))
                .build();
    }

    /**
     * 配置Swagger信息  = apiInfo
     *
     * @return 返回 ApiInfo 对象
     */
    @Bean
    public ApiInfo apiInfo() {
        Contact contact = new Contact("icanci", "https://icanci.oschina.io/", "icanci@foxmail.com");
        return new ApiInfo(
                "JUST-Admin-Web-API",
                "Just Do It",
                "v1.0",
                "https://icanci.oschina.io/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }
}